package com.bit.demo3;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-04
 * Time: 20:00
 */

class Animal {
    public String name;
    public int age;
    protected int count;

    public Animal(String name, int age){
        eat();
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println(name + "animal eat");
        //System.out.println(count);
    }
}
class Dog extends Animal {

    public Dog(String name, int age){
        super(name, age);
    }

    @Override
    public void eat(){
        System.out.println(name + "狼吞虎咽的eat");
    }

    public void func(int a){
        System.out.println("int");
    }

    public void func(int a, int b){
        System.out.println("int, int");
    }

    public void func(int a, int b, int c){
        System.out.println("int int int");
    }

}
class Bird extends Animal {
    public String wing;
    //public String name;

    public Bird(String name, int age, String wing){
        super(name, age);
        this.wing = wing;
    }

    public void fly(){
        System.out.println(name + "fly" + age);
    }
}
public class Test {

    public static void main(String[] args) {
        Dog animal = new Dog("heihei", 29);
    }

    public static void main5(String[] args) {
        Animal animal = new Dog("heihei", 29);
        if (animal instanceof Bird) {
            Bird bird = (Bird) animal;
            bird.fly();
        }
    }
    public static void main4(String[] args) {
        Animal animal = new Bird("heihei", 29, "我要的飞翔");
        Bird bird = (Bird)animal;
        bird.fly();
    }

    //静态绑定：根据你给的参数类型和个数推导出你调用哪个参数
    public static void main3(String[] args) {
        Dog dog = new Dog("haha", 16);
        dog.func(12);
    }
    //动态绑定：
    //1.父类引用 引用子类的对象
    //2.通过这个父类引用 调用父类 和 子类 同名的覆盖方法
       //重写：1.方法名相同 2.返回值相同 - 斜变类型也OK 3.参数列表相同 4.父子类关系
    //3.静态方法不能重写，也就不能动态绑定
    //4.子类的访问修饰限定符要 >= 父类的访问修饰限定符
    //5.private方法不能够重写
    //6.final修饰的也不能重新
    //通过父类引用，只能访问父类自己的成员

    //多态：
    //1.通过子类对父类方法的覆盖实现多态 - 运行时多态
    //2.利用重载来实现多态，即在同一个类中定义多个同名的不同方法来实现多态 - 编译型多态
    public static void main2(String[] args) {
        Animal animal = new Dog("haha",19);
        animal.eat();
    }

    public static void func(Animal animal){

    }

    public static Animal func2(){
        Dog dog = new Dog("haha", 16);
        return dog;//向上转型
    }

    public static void main1(String[] args) {
        Animal animal = new Dog("haha",19);
        //向上转型 - 父类引用指向子类对象
        Dog dog = new Dog("haha", 16);
        func(dog);
    }
}

